package com.treeman.user;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "USER_ROLE")
public class UserRole {

	public enum Role {
		ROLE_ANONYMOUSE, ROLE_USER, ROLE_PREMIUM_USER, ROLE_ADMIN
	}

	@Id
	@Column(name = "ROLE_ID")
	@SequenceGenerator(name = "role_id_gen", sequenceName = "role_id_sequence", allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "role_id_gen")
	private Long id;

	/**
	 * Enumerated - do bazy zostanie wpisany nazwa enum Role
	 */

	@Enumerated(EnumType.STRING)
	@Basic(optional = false)
	@Column(name = "ROLE", nullable = false)
	private Role role;

	/**
	 * Relacja many to one
	 * 
	 * USER_ROLE 1..* -------------- 1 USER
	 * 
	 */

	@Basic(optional = false)
	@ManyToOne(targetEntity = User.class)
	@JoinColumn(name = "USER_ID", nullable = false)
	private User user;

	/**
	 * Domyślny konstruktor, ustawia role na user
	 */
	public UserRole() {
		this.role = Role.ROLE_USER;
	}

	public UserRole(Role role) {
		this.role = role;
	}

	public Long getId() {
		return id;
	}

	public Role getRole() {
		return role;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

}
